﻿Public Class CrashReporter
    Public Sub New(ByVal e As Exception)

        ' Dieser Aufruf ist für den Designer erforderlich.
        InitializeComponent()

        ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu.
        If Not String.IsNullOrEmpty(e.GetType.ToString) Then
            textbox1.Text += "Typ: " + e.GetType.ToString + vbCrLf
        End If
        If Not String.IsNullOrEmpty(e.Message) Then
            textbox1.Text += "Message: " + e.Message + vbCrLf
        End If
        If Not String.IsNullOrEmpty(e.HelpLink) Then
            textbox1.Text += "Help Link: " + e.HelpLink + vbCrLf
        End If
        If e.TargetSite IsNot Nothing Then
            textbox1.Text += "Target: " + e.TargetSite.ToString + vbCrLf
        End If
        textbox1.Text += vbCrLf
        textbox1.Text += e.StackTrace
        Dim temp As String = vbCrLf
        
        temp += "Current Date/Time: " + DateTime.Now.ToString() + vbCrLf
        temp += "OS: " + Environment.OSVersion.VersionString + vbCrLf
        temp += "Language: " + System.Threading.Thread.CurrentThread.CurrentUICulture.NativeName + vbCrLf
        temp += "Biller Version: " + Window1.Version.ToString + vbCrLf
        temp += "Report the text of the 2nd Tab here: http://biller.codeplex.com/workitem/list/basic"
        TextBlock2.Text = temp

        FuncClasses.Log.AddError(textbox1.Text)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        If CheckBox1.IsChecked Then
            Process.Start(Application.ResourceAssembly.Location)
        End If
        Process.GetCurrentProcess().Kill()
    End Sub
    Dim updater As FuncClasses.UpdateProvider
    Private Sub Button2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button2.Click
        updater = New FuncClasses.UpdateProvider(Dispatcher)
        AddHandler updater.Update, AddressOf Update
        AddHandler updater.NoUpdate, AddressOf NoUpdate
        AddHandler updater.CloseApplication, AddressOf CloseApplication
        updater.AddFile(New FuncClasses.UpdateFileInfo("Biller.exe", "Hauptprogramm", Window1.Version, "", True))
    End Sub

    Public Sub Update(file As FuncClasses.UpdateFileInfo, version As Decimal)
        If file.Filename = "Biller.exe" Then
            If MessageBox.Show("Update available. Install?", "Update available", MessageBoxButton.YesNo) = MessageBoxResult.Yes Then
                updater.InstallUpdate(file)
            End If
        End If
        MessageBox.Show("No update available. Send the error code to biller@lastelb.com and wait for an update.", "No update available", MessageBoxButton.OK)
    End Sub

    Public Sub NoUpdate(file As FuncClasses.UpdateFileInfo)
        If file.Filename = "Biller.exe" Then
            MessageBox.Show("No update available. Send the error code to biller@lastelb.com and wait for an update.", "No update available", MessageBoxButton.OK)
        End If
    End Sub

    Public Sub CloseApplication()
        Process.GetCurrentProcess.Kill()
    End Sub
End Class
